package com.teacher.pc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.classfraction.ClassFractionGetDto;
import com.teacher.pojo.dto.classfraction.ClassFractionUpdateDto;
import com.teacher.pojo.entity.ClassFraction;
import com.teacher.pojo.vo.classfraction.ClassFractionGetVo;
import com.teacher.service.IClassFractionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 班级评分 前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-08-13
 */
@RestController
@RequestMapping("/pc/class-fraction")
public class ClassFractionController {

    @Autowired
    private IClassFractionService iClassFractionService;

    /**
     * 初始化班级评分
     *
     * @param classId
     * @return
     */
    @PostMapping("/{classId}")
    @ApiOperation("初始化班级评分 classFraction_initialize   老师评分（满分2分） 测评小组 满分 1分")
    @PreAuthorize("hasAuthority('classFraction_initialize')")
    public CommonResult<String> init(@PathVariable("classId") Long classId) {
        return iClassFractionService.init(classId);
    }

    /**
     * 更新德育基础分
     *
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("更新班级评分 classFraction_update")
    @PreAuthorize("hasAuthority('classFraction_update')")
    public CommonResult<String> update(@RequestBody @Validated ClassFractionUpdateDto dto) {
        ClassFraction classFractionBasic = new ClassFraction();
        BeanUtils.copyProperties(dto, classFractionBasic);
        if (iClassFractionService.updateById(classFractionBasic)) {
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");
    }

    /**
     * 查询德育基本分
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询班级评分 classFraction_get")
    @PreAuthorize("hasAuthority('classFraction_get')")
    public CommonResult<IPage<ClassFractionGetVo>> getPage(ClassFractionGetDto dto) {
        return iClassFractionService.getPage(dto);
    }

}

